package com.edu.zju.scs.panacea.utils;

import java.sql.Date;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @Author: Yue Liang
 * @Date: 2019-01-04 18:40
 */
public class DateUtil {
    public static java.util.Date toDate(String dateWithOctothorpe) {
        String dateStr = dateWithOctothorpe.replace('#', ' ');
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            java.util.Date utilDate = sdf.parse(dateStr);
            return utilDate;
        } catch (ParseException e) {
            // todo 打日志
        }
        return null;

    }

    public static Date toSqlDate(String dateStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            java.util.Date utilDate = sdf.parse(dateStr);
            Long time = utilDate.getTime();
            return new Date(time + 60000*60*24) ;
        } catch (ParseException e) {
            // todo 打日志
        }
        return null;

    }


    public static Time toSqlTime(String timeStr) {
        SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
        try {
            java.util.Date utilDate = sdf.parse(timeStr);
            Long time = utilDate.getTime();
            return new Time(time);
        } catch (ParseException e) {
            // todo 打日志
        }
        return null;

    }



    public static void main(String[] args) throws ParseException{
        System.out.println(toDate("2019-02-08#11:19:12"));
    }
}
